const connection = require("../db");

const getMusicLists = (req, res, next) => {
  const sql = "select * from music_list";
  // 获取token
  connection.query(sql, (err, result) => {
    if (err) return res.json({ success: false, error: err });
    return res.status(200).json({
      success: true,
      data: result,
      message: "操作成功",
    });
  });
};

const getMusicById = (req, res, next) => {
  const { id } = req.params;
  const sql = "select * from music_list where id = " + id;
  // 获取token
  connection.query(sql, (err, result) => {
    if (err) return res.json({ success: false, error: err });
    return res.status(200).json({
      success: true,
      data: result && result[0],
      message: "操作成功",
    });
  });
};

module.exports = { getMusicLists, getMusicById };
